/****************************************************************************************************
* 
*   TITLE: International Intervention and the Rule of Law after Civil War: Replication Files (Part 1)
*   AUTHOR: Robert A. Blair
*
****************************************************************************************************/
		
	
	* Set directory
	
						*cd  "YOUR DIRECTORY"
						
						cd "/Users/robertblair/Dropbox (Personal)/Documents/Research/Quant/Paper/Submissions/IO Acceptance/Analysis Replication Files"
						
		
		
	* Import 2010 residents survey data
		
						use survey-r2_res.dta, clear
		
		
		
	* Set weights *
	
						svyset [pweight=pweight], psu(commcode) strata(county)			

						
						
	* Set globals 
				
					
						gl R2_C_UNMIL r2_l_cunmil_week r2_l_cunmil_month r2_l_cunmil_rare r2_l_cunmilpala r2_l_cunmilmaintain	
																								
						gl R1_C_CONTROLS r1_l_ctownpop r1_l_croad_dist_rainy r1_l_cmobilec r1_l_cfacilities r1_l_cany_resources r1_l_cfreq_visitpol r1_l_cfreq_visitngo r1_c_cwealthindex r1_c_cviol_experienced r1_c_cdisp_ref r1_l_ctownexcm r1_l_cany_majorconf 
																						
						gl R2_I_CONTROLS r2_c_age_imputed r2_c_male r2_c_yrs_edu r2_c_minority r2_c_farmocc r2_c_disp_ref 

						gl PRE_2004_CONTROLS ofhouses school_yes health_yes wdaccessinwet_yes acled_numincidents
																				
						gl DISTRICTS district_fe*
					
					

	* Compute marginal effects for Figure 1							
													
						local title "r2_res_freqtype_pref_mlogit_margins"
						
						cap erase `title'.txt

						svy: mlogit r2_c_pref_all $R2_C_UNMIL $R2_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
							qui margins, dydx($R2_C_UNMIL) predict(outcome(State)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r2_c_pref_all, State) 
						svy: mlogit r2_c_pref_all $R2_C_UNMIL $R2_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
							qui margins, dydx($R2_C_UNMIL) predict(outcome(Local)) post
								outreg2 using `title', append noaster noparen noobs dec(2)  ctitle(r2_c_pref_all, Local) 
						svy: mlogit r2_c_pref_all $R2_C_UNMIL $R2_I_CONTROLS $R1_C_CONTROLS $DISTRICTS	
							qui margins, dydx($R2_C_UNMIL) predict(outcome(UNMIL)) post
								outreg2 using `title', append noaster noparen noobs dec(2)  ctitle(r2_c_pref_all, UNMIL) 
							

									
	* Compute marginal effects for Figure 2
																					
						local title "r2_res_anyres_pref_mlogit_margins"
						
						cap erase `title'.txt

						svy: mlogit r2_c_pref_all r2_c_unmil_time $R2_I_CONTROLS $PRE_2004_CONTROLS $DISTRICTS	
							margins, dydx(r2_c_unmil_time) predict(outcome(State)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r2_c_pref_all, State) 
						svy: mlogit r2_c_pref_all r2_c_unmil_time $R2_I_CONTROLS $PRE_2004_CONTROLS $DISTRICTS	
							margins, dydx(r2_c_unmil_time) predict(outcome(Local)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r2_c_pref_all, Local)
						svy: mlogit r2_c_pref_all r2_c_unmil_time $R2_I_CONTROLS $PRE_2004_CONTROLS $DISTRICTS	
							margins, dydx(r2_c_unmil_time) predict(outcome(UNMIL)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r2_c_pref_all, UNMIL) 						
				
						
				
	* Replicate Table 2
						
						local title "Table2"
						
						cap erase `title'.xls
						cap erase `title'.txt

						foreach y of varlist r2_c_statecorr r2_c_statesame_not r2_c_leadcorr r2_c_leadsame_not r2_c_unmilcorr r2_c_unmilsame_not {
							local lab : var label `y'
							svy: reg `y' $R2_C_UNMIL $R2_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
								outreg2 using `title'.xls, append excel ctitle(`lab') aster(se) dec(2) br nocons keep($R2_C_UNMIL)
							}
							

						
						
	* Replicate Table 3
						
						local title "Table3"
						
						cap erase `title'.xls
						cap erase `title'.txt

						foreach y of varlist r2_c_statecorr r2_c_statesame_not r2_c_leadcorr r2_c_leadsame_not r2_c_unmilcorr r2_c_unmilsame_not {
							local lab : var label `y'
							svy: reg `y' r2_c_unmil_time $R2_I_CONTROLS $PRE_2004_CONTROLS $DISTRICTS		
									outreg2 using `title'.xls, append excel ctitle(`lab') aster(se) dec(2) br nocons keep(r2_c_unmil_time)
							}
							
						
	
	* Clear
	
						clear
						
						

	* Import 2012 residents survey data
		
						use survey-r3_res.dta, clear
		
		
		
	* Set weights
	
						svyset [pweight=pweight], psu(commcode) strata(county)			

	
	* Set globals

										
						gl R2_C_UNMIL r2_l_cunmil_week r2_l_cunmil_month r2_l_cunmil_rare r2_l_cunmilpala r2_l_cunmilmaintain 					
	
						gl R1_C_CONTROLS r1_l_ctownpop r1_l_croad_dist_rainy r1_l_cmobilec r1_l_cfacilities r1_l_cany_resources r1_l_cfreq_visitpol r1_l_cfreq_visitngo r1_c_cwealthindex r1_c_cviol_experienced r1_c_cdisp_ref r1_l_ctownexcm r1_l_cany_majorconf
																	
						gl R3_I_CONTROLS r3_c_age_imputed r3_c_male r3_c_yrs_edu r3_c_minority r3_c_farmocc r3_c_disp_ref 
						
						gl PRE_2004_CONTROLS ofhouses school_yes health_yes wdaccessinwet_yes acled_numincidents
	
						gl DISTRICTS district_fe*
											

					
	
	* Replicate Table 1
							
						local title "Table1"
						
						cap erase `title'.xls
						cap erase `title'.txt

						foreach y of varlist r3_c_local_top r3_c_state_top r3_c_unmil_top {
							svy: ivregress 2sls `y' $R3_I_CONTROLS $PRE_2004_CONTROLS (r3_c_unmil_time = distcomm_para_i) if distcomm_border<=20
								outreg2 using `title'.xls, ///
									append label excel ctitle(`lab') aster(se) dec(2) br nocons keep(r3_c_unmil_time)
									}
													

													
	* Compute marginal effects for Figure 4
							
						local title "r3_res_freqtype_pref_mlogit_margins"
						
						cap erase `title'.xls
						cap erase `title'.txt

						svy: mlogit r3_c_pref_all $R2_C_UNMIL $R3_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
							qui margins, dydx($R2_C_UNMIL) predict(outcome(State)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r3_c_pref_all, State) 
						svy: mlogit r3_c_pref_all $R2_C_UNMIL $R3_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
							qui margins, dydx($R2_C_UNMIL) predict(outcome(Local)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r3_c_pref_all, Local) 
						svy: mlogit r3_c_pref_all $R2_C_UNMIL $R3_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
							qui margins, dydx($R2_C_UNMIL) predict(outcome(UNMIL)) post
								outreg2 using `title', append noaster noparen noobs dec(2) ctitle(r3_c_pref_all, UNMIL) 
							


	* Replicate Table 4						
	
					
						local title "Table4"
						
						cap erase `title'.xls
						cap erase `title'.txt

						foreach y of varlist r3_c_statecorr r3_c_statesame_not r3_c_leadcorr r3_c_leadsame_not r3_c_unmilcorr r3_c_unmilsame_not {
							local lab : var label `y'
							svy: reg `y' $R2_C_UNMIL $R3_I_CONTROLS $R1_C_CONTROLS $DISTRICTS		
								qui margins, dydx($R2_C_UNMIL) post
								outreg2 using `title'.xls, ///
									append label excel ctitle(`lab') aster(se) dec(2) br nocons keep($R2_C_UNMIL)
							}
							

						
